package com.alcargo.actions;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.sql.DataSource;

import org.apache.log4j.Logger;

import com.alcargo.dao.NouseDao;
import com.alcargo.model.NoUsefulModel;
import com.alcargo.model.db.AirWayBill;
import com.alcargo.service.NouseService;
import com.opensymphony.xwork2.ActionSupport;

public class NoUsefulAction extends ActionSupport{
	/**
	 * 
	 */
	private static final long serialVersionUID = -1296031500184546492L;
	Logger logger = Logger.getLogger(this.getClass());
	private String username;
	private String password;
	private NoUsefulModel sample;
	private DataSource dataSource ;
	private NouseDao nouseDao;
	private NouseService nouseService;
	public NouseDao getNouseDao() {
		return nouseDao;
	}
	public void setNouseDao(NouseDao nouseDao) {
		this.nouseDao = nouseDao;
	}
	public NouseService getNouseService() {
		return nouseService;
	}
	public void setNouseService(NouseService nouseService) {
		this.nouseService = nouseService;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String login(){
		return SUCCESS;
	}
	public String springMao(){
		logger.info("no useful action in spring is begin");
		this.password = sample.getHello();
		logger.info(username);
		
		return SUCCESS;
	}
	public String springService() throws SQLException{
		logger.info("no useful action in spring is begin");
		AirWayBill a = nouseService.getAirWayBillbyNo(username);
		if(a==null){
			password = "not in db";
		}
		logger.info(username);
		
		return SUCCESS;
	}
	public String connDataBase() throws SQLException {
		Connection conn = null;
		Statement st = null;
		ResultSet rs = null;
		try{
		 conn = dataSource.getConnection();
		 st = conn.createStatement();
		 rs = st.executeQuery("select * from accounts");
		if(rs.next()){
			username = rs.getString(1);
			password = rs.getString(2);
		}
		}catch(SQLException e){
			
		}finally{
			rs.close();
			st.close();
			conn.close();
			
		}
		return SUCCESS;
	}

	public DataSource getDataSource() {
		return dataSource;
	}
	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}
	public NoUsefulModel getSample() {
		return sample;
	}
	public void setSample(NoUsefulModel sample) {
		this.sample = sample;
	}

}
